package cn.zf233.jwtshiro.web;

import cn.zf233.jwtshiro.util.JwtUtil;
import org.apache.commons.lang.StringUtils;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.subject.Subject;

/**
 * Created by zf233 on 2021/7/12
 */
public class BaseController {

    public Long loadUser() {
        Subject currentUser = SecurityUtils.getSubject();
        String token = (String) currentUser.getPrincipal();
        if (StringUtils.isBlank(token)) {
            return -1L;
        }
        return JwtUtil.getUserIdByToken(token);
    }
}
